package com.itheima.reggie;

import com.itheima.reggie.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @author ：sean
 * @date ：Created in 2022/5/16
 * @description ：启动类
 * @version: 1.0
 */
@SpringBootApplication
@Slf4j
@ServletComponentScan
@EnableTransactionManagement
@EnableCaching  // 启用SpringCache缓存注解
public class ReggieApplication {
	public static void main(String args[]){
		log.info("[启动瑞吉项目]");
		//testSaveString();
		//testSaveObject();

		SpringApplication.run(ReggieApplication.class,args);
	}
	public static void testSaveString(){
		try{
			String keyString = "world";

			File fileString = new File("D:\\upload\\test","test-string.data");
			// 字符串文本写入文件
			FileOutputStream fos = new FileOutputStream(fileString);
			//fos.write(keyString.getBytes("utf-8"));
			fos.close();
		}catch(Exception e){
		    e.printStackTrace();
		}

	}
	public static void testSaveObject(){
		try{
			String keyString = "world";
			User user = new User();
			user.setPhone("13311002200");
			// 把字符串以对象形式写入文件，一定用到对象输出流，这个对象的类一定要做一个事？（序列化）
			File fileObj = new File("D:\\upload\\test","test-obj.data");
			FileOutputStream fos = new FileOutputStream(fileObj);
			// 对象输出流
			ObjectOutputStream oos = new ObjectOutputStream(fos);
			// 把对象进行序列化
			//oos.writeObject(keyString);
			oos.writeObject(user);
			oos.close();
		}catch(Exception e){
		    e.printStackTrace();
		}

	}
}
